<?php
/**
 * Created by PhpStorm.
 * User: wangzl
 * Date: 2018/11/21
 * Time: 11:19 AM
 */

/**
 * @param $data
 * @param $flag
 * @param bool $flush
 * @return bool
 */
function mylog($data, $flag, $flush = false) {
    $file = storage_path() . '/debug/' . date('Ymd'). '.log';
    if(!is_dir(dirname($file))) {
        mkdir(dirname($file), 0777, true);
    }
    if($flush) {
        file_put_contents($file, '');
        return true;
    }
    ob_start();
    echo '------------------' . $flag . '-------------------';
    echo "\n";
    echo 'Date: '.date('Y-m-d H:i:s');
    echo "\n";
    echo 'File: '.$_SERVER['PHP_SELF'];
    echo "\n";
    print_r($data);
    echo "\n\n";
    $o = ob_get_contents();
    ob_end_clean();
    file_put_contents($file, $o, 8);
    return true;
}